/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.scene.service;

import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.service.CrudService;
import com.lczyfz.istep.modules.scene.dao.SceneSubnetDao;
import com.lczyfz.istep.modules.scene.entity.SceneNetwork;
import com.lczyfz.istep.modules.scene.entity.SceneRouter;
import com.lczyfz.istep.modules.scene.entity.SceneSubnet;
import com.lczyfz.istep.modules.sys.entity.User;
import com.lczyfz.istep.modules.sys.utils.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 子网管理Service
 * @author dh
 * @version 2017-03-25
 */
@Service
@Transactional(readOnly = true)
public class SceneSubnetService extends CrudService<SceneSubnetDao, SceneSubnet> {

	public SceneSubnet get(String id) {
		return super.get(id);
	}
	
	public List<SceneSubnet> findList(SceneSubnet sceneSubnet) {
		return super.findList(sceneSubnet);
	}
	
	public Page<SceneSubnet> findPage(Page<SceneSubnet> page, SceneSubnet sceneSubnet) {
		return super.findPage(page, sceneSubnet);
	}
	
	@Transactional(readOnly = false)
	public void save(SceneSubnet sceneSubnet) {
		super.save(sceneSubnet);
	}
	
	@Transactional(readOnly = false)
	public void delete(SceneSubnet sceneSubnet) {
		super.delete(sceneSubnet);
	}

	public List<SceneSubnet> getSubnetListByRouterId(SceneSubnet sceneSubnet)
	{
		return  dao.getSubnetListByRouterId(sceneSubnet);
	}

	/**
	 * 根据路由id查询子网列表
	 * @param page
	 * @param sceneSubnet
	 * @return
	 */
	public Page<SceneSubnet> findPageByRouterId(Page<SceneSubnet> page,SceneSubnet sceneSubnet) {
		sceneSubnet.setPage(page);
		page.setList(dao.getSubnetListByRouterId(sceneSubnet));
		return page;
	}
	/**
	 * 根据网络id查询子网列表
	 * @param page
	 * @param sceneSubnet
	 * @return
	 */
	public Page<SceneSubnet> findPageByNetworkId(Page<SceneSubnet> page,SceneSubnet sceneSubnet) {
		sceneSubnet.setPage(page);
		page.setList(dao.findList(sceneSubnet));
		return page;
	}

	@Transactional(readOnly = false)
	public void insert(SceneSubnet sceneSubnet) {
		logger.debug("networkIdinsert=== [{}]", sceneSubnet.getId());

		dao.insert(sceneSubnet);
	}
	public void preInsert(SceneSubnet preInfo) {

		User user = UserUtils.getUser();
		if (StringUtils.isNotBlank(user.getId())) {
			preInfo.setUpdateBy(user);
			preInfo.setCreateBy(user);
		}
		Date date=new Date();
		preInfo.setUpdateDate(date);
		preInfo.setCreateDate(date);

	}
	@Transactional(readOnly = false)
	public  void  deleteByNetworkId(SceneSubnet sceneSubnet)
	{
		dao.deleteByNetworkId(sceneSubnet);
	}
	public List<SceneSubnet> findSubnetListByNetworkId(SceneNetwork sceneNetwork)
	{
		return dao.findSubnetListByNetworkId(sceneNetwork);
	}
	public List<SceneSubnet> getRouterSubnetListByRouterId(SceneRouter sceneRouter)
	{
		return dao.getRouterSubnetListByRouterId(sceneRouter);
	}
	public List<SceneSubnet> findRouterSubnet(String routerId,String subnetId){
		return dao.findRouterSubnet(routerId,subnetId);
	}



}